/*
* Filename:
* Summary:	
*
* Author:
* Version:
* Finished time:
*/
#include "head.h"
#include "config.h"
#include "popmenu.h"
#include "eggtrayicon.h"
#include "ipmsg.h"
#include "trayicon.h"
#include "mainwindow.h"
/*
*callback function
*/
gboolean tray_button_press_event (GtkWidget * button, GdkEventButton * event)
{
#ifdef _DEBUG
	printf("Enter tray_button_press_event\nEventtype is %d\n",event->button);
#endif
	g_return_val_if_fail ((event->type == GDK_BUTTON_PRESS), FALSE); /* ignore double-click or any others */

	switch ( event->button )
	{
		case LEFT_BUTTON:

			/* show main window */
			gtk_widget_show(GTK_WIDGET(main_window));
			break;

		case MIDDLE_BUTTON:
			break;

		case RIGHT_BUTTON:
			/* popup menu */
#ifdef _DEBUG
			printf("try to popmenu\n");
#endif
			gtk_menu_popup(GTK_MENU(pop_menu), NULL, NULL, NULL, NULL,
				       event->button, event->time);
			break;

		default:
			return FALSE;
	}

	return TRUE;
}
/*
* Function:
* Summary:
*
* Argument:
* 1th argument --
* 2th argument --
*
* Return:
*  
*/
GtkWidget *load_image (const gchar * filename)
{
	GtkWidget *image;
	GdkPixbuf *pixbuf;

	pixbuf = gdk_pixbuf_new_from_file (filename, NULL);
	if ( !pixbuf )
	{
		image = gtk_image_new_from_stock (GTK_STOCK_HOME,
						  GTK_ICON_SIZE_MENU);
	} else
	{
		image = gtk_image_new_from_pixbuf (pixbuf);
	}

	return image;
}


/*
* Function:
* Summary:
*
* Argument:
* 1th argument --
* 2th argument --
*
* Return:
*  
*/
void NewTrayIcon()
{
	GtkWidget *image;
	GtkWidget *event_box;
	GtkTooltips *tooltips;
	EggTrayIcon *tray_icon;

	tooltips = gtk_tooltips_new ();
	tray_icon = egg_tray_icon_new ("Ipmsg tray icon");

	event_box = gtk_event_box_new ();
	gtk_container_add (GTK_CONTAINER (tray_icon), event_box);
	g_signal_connect (G_OBJECT (event_box), "button-press-event",
			  G_CALLBACK (tray_button_press_event), NULL);
	gtk_tooltips_set_tip (GTK_TOOLTIPS(tooltips), event_box,
			      _("Try a left/right click"), NULL);

	image = load_image ("ipmsg16x16.xpm");
	gtk_container_add (GTK_CONTAINER (event_box), image);

	gtk_widget_show_all (GTK_WIDGET (tray_icon));

	return;
}
